﻿/// ---------------------------------------------
///
/// ---------------------------------------------

///---------------------------

//双击事件
function CustomDbClick() {
    //parent.closeWin(); //去掉双击功能
    fnViewVation();
}


//添加信息
var fnCustomAdd = function () {
    const_EditEntity = "wkVacation";
    document.getElementById("dialog1_h").innerHTML = "新增假期";
    document.getElementById("EditUIWindow").src = "AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=add";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//修改信息
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "wkVacation";
    document.getElementById("dialog1_h").innerHTML = "修改假期—" + record._oData["Name"];
    document.getElementById("EditUIWindow").src = "AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=edit" + "&id=" + record.getData(const_entityID);
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//删除第一步
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //debugger;
    var id = record.getData(const_entityID);
    //第一步先判断是否有引用
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/workTimeAjax.aspx?flag=deletevation&id=" + id, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    //第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                    }
                    SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
                    YAHOO.example.container.dialog3.show();
                }
                else if (str == "0") {
                    alert("该假期类型已经被引用，不能删除！");
                    return;
                }
                else if (str == "-1") {
                    alert("该假期类型ID为空，删除失败！");
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}

//查看
var fnViewVation = function () {    
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "wkVacation";
    document.getElementById("dialog1_h").innerHTML = "查看假期—" + record._oData["Name"];
    document.getElementById("EditUIWindow").src = "AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=view" + "&id=" + record.getData(const_entityID);
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}


//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {

    });
}


